package com.sun.java8;


import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

/**
 * @FunctionalInterface public interface Supplier<T> {
 * T get();
 * }
 * <p>
 * 无参  有返回值
 */
public class SupplierTest {
    public static void main(String[] args) {
        showAll(()->{
            int arr[] = {22,33,21,56,65};

            Arrays.sort(arr);
            return arr[arr.length - 1];
        });
        String flag = getMap(() -> {
            Map map = new HashMap();
            map.put("k1", "v1");
            map.put("k2", "v2");
            map.put("k3", "v3");
            return map;
        });
        if (flag.equals("1")){
            System.out.println("================");
        }else {
            System.out.println("++++++++++++++++++");
        }
    }
    public static void showAll(Supplier<Integer> supplier){
        Integer max = supplier.get();
        System.out.println("最大值:" + max);
    }
    public static String  getMap(Supplier<Map> supplier){
        Map map = supplier.get();
        System.out.println("获得map=" + map);
        return "1";
    }
}
